class Solution(object):
    def gameOfLife(self, board):
        """
        :type board: List[List[int]]
        :rtype: void Do not return anything, modify board in-place instead.
        """
        nRow = len(board)
        nCol = len(board[0])
        tmp = [[0 for _ in range(nCol)] for _ in range(nRow)]
        for r in range(nRow):
            for c in range(nCol):
                if board[r][c]==1:
                    if r-1>=0:
                        tmp[r-1][c] += 1
                    if r+1<nRow:
                        tmp[r+1][c] += 1
                    if c-1>=0:
                        tmp[r][c-1] += 1
                    if c+1<nCol:
                        tmp[r][c+1] += 1
                    if r-1>=0 and c-1>=0:
                        tmp[r-1][c-1] += 1
                    if r+1<nRow and c+1<nCol:
                        tmp[r+1][c+1] += 1
                    if r-1>=0 and c+1<nCol:
                        tmp[r-1][c+1] += 1
                    if r+1<nRow and c-1>=0:
                        tmp[r+1][c-1] += 1
        for r in range(nRow):
            for c in range(nCol):
                if tmp[r][c]<2 or tmp[r][c]>3:
                    board[r][c]=0
                elif tmp[r][c]==3:
                    board[r][c]=1